<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <meta name="description" content="简述vue和django的工作流程，django中间件的作用以及请求顺序
中间件是介于request 和 response 处理之间的一道处理过程，用于全局范围改变Django的输入和输出，简单的来说中间件是帮助我们在视图函数指向之前和执行之后都可以做一些额外的操作 
Django项目中默认启用了c" />
  

  
  
  
  
  
  
  <title>简述vue和django的工作流程 | 南辞的技术博客</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="简述vue和django的工作流程，django中间件的作用以及请求顺序 中间件是介于request 和 response 处理之间的一道处理过程，用于全局范围改变Django的输入和输出，简单的来说中间件是帮助我们在视图函数指向之前和执行之后都可以做一些额外的操作  Django项目中默认启用了csrf保护，每次请求通过csrf中间件检查请求是否是有正确的token值；当用户发送请求时，通过自定">
<meta property="og:type" content="article">
<meta property="og:title" content="简述vue和django的工作流程">
<meta property="og:url" content="https://yanlidoushikeke.gitee.io/myhexo/2021/01/21/%E7%AE%80%E8%BF%B0vue%E5%92%8Cdjango%E7%9A%84%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B/index.html">
<meta property="og:site_name" content="南辞的技术博客">
<meta property="og:description" content="简述vue和django的工作流程，django中间件的作用以及请求顺序 中间件是介于request 和 response 处理之间的一道处理过程，用于全局范围改变Django的输入和输出，简单的来说中间件是帮助我们在视图函数指向之前和执行之后都可以做一些额外的操作  Django项目中默认启用了csrf保护，每次请求通过csrf中间件检查请求是否是有正确的token值；当用户发送请求时，通过自定">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2021-01-21T08:41:31.000Z">
<meta property="article:modified_time" content="2021-01-21T08:42:25.612Z">
<meta property="article:author" content="南辞">
<meta name="twitter:card" content="summary">
  
  
    <link rel="icon" href="/tefuir/css/images/favicon.ico">
  
  
<link rel="stylesheet" href="/tefuir/css/style.css">

  

  
  <!-- baidu webmaster push -->
  <script src='//push.zhanzhang.baidu.com/push.js'></script>
<meta name="generator" content="Hexo 5.2.0"><link rel="alternate" href="/tefuir/atom.xml" title="南辞的技术博客" type="application/atom+xml">
</head>
<body class="home blog custom-background custom-font-enabled single-author">
  <div id="page" class="hfeed site">
      <header id="masthead" class="site-header" role="banner">
    <hgroup>
      <h1 class="site-title">
        <a href="/tefuir/" title="南辞的技术博客" rel="home">南辞的技术博客</a>
      </h1>
      
        <h2 class="site-description hitokoto"></h2>
        <script type="text/javascript" src="https://v1.hitokoto.cn/?encode=js"></script>
      
    </hgroup>

    <nav id="site-navigation" class="main-navigation" role="navigation">
            <button class="menu-toggle">菜单</button>
            <a class="assistive-text" href="/#content" title="跳至内容">跳至内容</a><!--TODO-->
            <div class="menu-main-container">
                <ul id="menu-main" class="nav-menu">
                
                    <li class="menu-item menu-item-type-post_type menu-item-object-page"><a href="/tefuir/">Home</a></li>
                
                    <li class="menu-item menu-item-type-post_type menu-item-object-page"><a href="/tefuir/archives">Archives</a></li>
                
                </ul>
            </div>
    </nav>
</header>

      <div id="main" class="wrapper">
        <div id="primary" class="site-content"><div id="content" role="main"><article id="post-简述vue和django的工作流程" class="post-简述vue和django的工作流程 post type-post status-publish format-standard hentry">
    <!---->

      <header class="entry-header">
        
        
  
    <h1 class="entry-title article-title">
      简述vue和django的工作流程
    </h1>
  

        
        <div class="comments-link">
            
            <a href="javascript:void(0);" data-url="https://yanlidoushikeke.gitee.io/myhexo/2021/01/21/%E7%AE%80%E8%BF%B0vue%E5%92%8Cdjango%E7%9A%84%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B/" data-id="ckkttwp6y0007csu08vjoeb0f" class="leave-reply bdsharebuttonbox" data-cmd="more">Share</a>
        </div><!-- .comments-link -->
      </header><!-- .entry-header -->

    <div class="entry-content">
      
        <h4 id="简述vue和django的工作流程，django中间件的作用以及请求顺序"><a href="#简述vue和django的工作流程，django中间件的作用以及请求顺序" class="headerlink" title="简述vue和django的工作流程，django中间件的作用以及请求顺序"></a>简述vue和django的工作流程，django中间件的作用以及请求顺序</h4><ul>
<li>中间件是介于request 和 response 处理之间的一道处理过程，用于全局范围改变Django的输入和输出，简单的来说中间件是帮助我们在视图函数指向之前和执行之后都可以做一些额外的操作 </li>
<li>Django项目中默认启用了csrf保护，每次请求通过csrf中间件检查请求是否是有正确的token值；当用户发送请求时，通过自定义的认证中间件，判断用户是否已经登录，未登录就去登录 </li>
</ul>
<p>注册：</p>
<p>class Register(View):<br>    def post(self,request):<br>        phone = request.POST.GET(‘phone’)<br>        img = request.POST.GET(‘img’)<br>        nick_name = request.POST.GET(‘nick_name’)<br>        obj_list = models.User.objects.filter(nick_name = nick_name)<br>        if obj_list:<br>            return HttpResponse({‘msg’: ‘用户已存在’,’code’:200})</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">models.User.objects.create(nick_name&#x3D;nick_name,img&#x3D;img,phone&#x3D;phone)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>获取数据</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">def Get(self, request):</span><br><span class="line">    user_liats &#x3D; models.User.objects.all()</span><br><span class="line">    user_liat &#x3D; []</span><br><span class="line">    for user_obj in user_liats:</span><br><span class="line">        user_liat.append(&#123;</span><br><span class="line">            &#39;phone&#39; : user_obj.phone,</span><br><span class="line">            &#39;img&#39; : user_obj.img,</span><br><span class="line">            &#39;nick_name&#39; : user_obj.nick_name,</span><br><span class="line">        &#125;)</span><br><span class="line">    return HttpResponse(user_liat)</span><br></pre></td></tr></table></figure>

<p>修改数据</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">def put(self, request):</span><br><span class="line">    data &#x3D; json.loads(request.body.decode())</span><br><span class="line">    phone &#x3D; data.GET(&#39;phone&#39;)</span><br><span class="line">    img &#x3D; data.GET(&#39;img&#39;)</span><br><span class="line">    nick_name &#x3D; data.GET(&#39;nick_name&#39;)</span><br><span class="line">    user_object &#x3D; models.User.objects.filter(nick_name&#x3D;nick_name,phone&#x3D;phone,img&#x3D;img).first()</span><br><span class="line">    user_object.nick_name &#x3D; nick_name</span><br><span class="line">    nick_name &#x3D; request.POST.GET(&#39;nick_name&#39;)</span><br><span class="line">    user_object.save()</span><br><span class="line">    return HttpResponse(&#123;&#39;msg&#39;: &#39;修改成功&#39;, &#39;code&#39;: 200&#125;)</span><br></pre></td></tr></table></figure>

<p>什么是RESTful？</p>
<ul>
<li>使用https来通信</li>
<li>域名（子域名方式或url方式）</li>
<li>版本（如果有版本在域名后加版本号）</li>
<li>面向资源编程（认为每个对象都是资源）</li>
<li>methods（GET POST PUT DELECT POTCH)</li>
<li>过滤，分页，排序：通过URL上传参的形式传递搜索条件</li>
<li>状态码</li>
</ul>

      
    </div><!-- .entry-content -->

    <footer class="entry-meta">
    <a href="/tefuir/2021/01/21/%E7%AE%80%E8%BF%B0vue%E5%92%8Cdjango%E7%9A%84%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B/">
    <time datetime="2021-01-21T08:41:31.000Z" class="entry-date">
        2021-01-21
    </time>
</a>
    
    
    </footer>
</article>


    
<nav class="nav-single">
    <h3 class="assistive-text">文章导航</h3>
    
        <span class="nav-previous"><a href="/tefuir/2021/02/06/%E9%AB%98%E5%B9%B6%E5%8F%91%E8%AF%A6%E8%A7%A3/" rel="prev"><span class="meta-nav">←</span> 高并发详解</a></span>
    
    
        <span class="nav-next"><a href="/tefuir/2021/01/19/selenium%E6%A8%A1%E6%8B%9F%E6%B3%A8%E5%86%8C%EF%BC%8C%E7%99%BB%E9%99%86%E4%BB%A5%E5%8F%8A%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81%E7%9A%84%E7%94%9F%E6%88%90/" rel="next">(no title) <span class="meta-nav">→</span></a></span>
    
</nav><!-- .nav-single -->







</div></div>
        <div id="secondary" class="widget-area" role="complementary">
  
    <aside id="search" class="widget widget_search"><form role="search" method="get" accept-charset="utf-8" id="searchform" class="searchform" action="//google.com/search">
    <div>
        <input type="text" value="" name="s" id="s" />
        <input type="submit" id="searchsubmit" value="搜索" />
    </div>
</form></aside>
  
    
  
    
  
    
  <aside class="widget">
    <h3 class="widget-title">Recents</h3>
    <div class="widget-content">
      <ul>
        
          <li>
            <a href="/tefuir/2021/04/26/python%E5%9F%BA%E7%A1%80%E7%90%86%E8%AE%BA%E5%AE%9D%E5%85%B8/">python基础理论宝典</a>
          </li>
        
          <li>
            <a href="/tefuir/2021/04/23/python3-Flask%E7%BB%93%E5%90%88Socket-io%E7%AE%80%E5%8D%95%E5%AE%9E%E7%8E%B0%E5%9C%A8%E7%BA%BF%E5%AE%A2%E6%9C%8D%E7%B3%BB%E7%BB%9F/">python3+Flask结合Socket.io简单实现在线客服系统</a>
          </li>
        
          <li>
            <a href="/tefuir/2021/04/23/win10%E7%B3%BB%E7%BB%9F%E4%B8%8B%E5%88%A9%E7%94%A8docker%E9%83%A8%E7%BD%B2gunicorn-Flask%E6%89%93%E9%80%A0%E7%8B%AC%E7%AB%8B%E9%95%9C%E5%83%8F/">win10系统下利用docker部署gunicorn+Flask打造独立镜像</a>
          </li>
        
          <li>
            <a href="/tefuir/2021/04/23/win10%E7%B3%BB%E7%BB%9F%E4%B8%8B%E5%9F%BA%E4%BA%8Edocker%E9%85%8D%E7%BD%AEelasticsearch%E9%85%8D%E5%90%88python3%E8%BF%9B%E8%A1%8C%E5%85%A8%E6%96%87%E6%A3%80%E7%B4%A2/">win10系统下基于docker配置elasticsearch配合python3进行全文检索</a>
          </li>
        
          <li>
            <a href="/tefuir/2021/04/23/%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%97%AE%E9%A2%98/">服务器问题</a>
          </li>
        
      </ul>
    </div>
  </aside>

  
    
  
    
  
</div>
      </div>
      <footer id="colophon" role="contentinfo">
    <p>&copy; 2021 南辞
    All rights reserved.</p>
    <p>Powered by <a href="http://hexo.io/" target="_blank">Hexo</a></p>
</footer>
    <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"1","bdMiniList":false,"bdPic":"","bdStyle":"2","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='/js/share.js'];</script>

<script src="/js/jquery-3.3.1.min.js"></script>


  
<link rel="stylesheet" href="/tefuir/fancybox/jquery.fancybox.css">

  
<script src="/tefuir/fancybox/jquery.fancybox.pack.js"></script>




<script src="/tefuir/js/script.js"></script>


<script src="/js/navigation.js"></script>

<div id="bg"></div>

  </div>
</body>
</html>